<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8" />
    <title>charAt()函数</title>
</head>
<body>
    <script>
    //访问字符下标从0开始
    var str = "yangtaoaixuexi";
    //计算字符串的长度
    document.write(str.length,"<br>");//14
    document.write(str.charAt(4),"<br>");//t
    document.write(str.charAt(str.length-1),"<br>");//i

    //访问出界或者负数则返回无输出
    document.write(str.charAt(-2));//""
    document.write(str.charAt(15));//""
    </script>
</body>
</html>